package com.qf.service.Impl;

import com.qf.feign.CacheService;
import com.qf.service.PushToClient;
import com.qf.utils.HttpUtil;
import com.qianfeng.smsplatform.common.constants.CacheConstants;
import com.qianfeng.smsplatform.common.model.Standard_Report;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * @author 徐老板
 * @date 2020/3/4   11:42
 */
@Service
public class PushToClientImpl implements PushToClient {
    //这个方法就是用来给客户端发送接收成功信息用的
    @Resource
    private CacheService cacheService;

    @Override
    public void sendReport(Standard_Report report) {
        //获取用户地址
        Map map = cacheService.hmget(CacheConstants.CACHE_PREFIX_CLIENT + report.getClientID());
        if (map!=null&&map.size()>0){
            String receivestatusurl = (String) map.get("receivestatusurl");//获取回调地址
            //发起请求,传递我们的结果
            //这里再封装map用于传递给用户
            Map<String, Object> paramsMap = new HashMap<>();
            paramsMap.put("srcId", report.getSrcID());
            paramsMap.put("mobile", report.getMobile());
            paramsMap.put("state", report.getState());
            paramsMap.put("errorCode", report.getErrorCode());
            //这个是用于向客户发送http请求的工具类 这个是新知识
            String result = HttpUtil.sendRequest(receivestatusurl, paramsMap, "get");
            System.err.println("返回结果:"+result);

        }
    }
}
